/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kmcsoft.goldshop.search;

import com.kmcsoft.goldshop.generic.service.ShopGenericService;
import com.kmcsoft.goldshop.model.master.Booth;
import com.kmcsoft.goldshop.model.master.DiamondColor;
import com.kmcsoft.goldshop.model.master.DiamondGroup;
import com.kmcsoft.goldshop.model.master.DiamondPure;
import com.kmcsoft.goldshop.model.master.Goldsmith;
import com.kmcsoft.goldshop.model.master.JewelryStyle;
import com.kmcsoft.goldshop.model.master.Product;
import com.kmcsoft.goldshop.model.master.ProductGold;
import com.kmcsoft.goldshop.model.master.Shop;
import com.kmcsoft.goldshop.search.service.SearchService;
import java.util.Collection;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Div;
import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Grid;

/**
 *
 * @author kmcsoft02
 */
public class ScmSearchComposer extends GenericForwardComposer {

    private AnnotateDataBinder binder;
    @Autowired
    private SearchService searchService;
    private DiamondColor diamondColor;
    private DiamondGroup diamondGroup;
    private DiamondPure diamondPure;
    private Goldsmith goldsmith;
    private Shop shop;
    private Booth booth;
    private JewelryStyle jewelryStyle;
    private int productType;
    private ProductGold productGold;
    private String totalWeightCondition;
    private Doublebox searchTotalWeightAmount;
    private String gemWeightCondition;
    private Doublebox searchGemWeightAmount;
    private String netWeightCondition;
    private Doublebox searchNetWeightAmount;
    private String wageCostCondition;
    private Doublebox searchWageCostAmount;
    private String wagePriceCondition;
    private Doublebox searchWagePriceAmount;
    private String gemPriceCondition;
    private Doublebox searchGemPriceAmount;
    private Collection<HashMap<String, String>> list;
    private Collection<Booth> booths;
    private Combobox searchBooth;
    private Combobox searchStlyes;
    private Combobox searchGoldSmith;
    private Combobox searchGold;
    private Combobox searchTotalWeightCondition;
    private Combobox searchNetWeightCondition;
    private Combobox searchWageCostCondition;
    private Combobox searchWagePriceCondition;
    private Combobox searchDiamondGroup;
    private Combobox searchDiamondColor;
    private Combobox searchDiamondPure;
    @Autowired
    private ShopGenericService shopGenericService;
    private Div detailDiv;
    private Grid leftGrid;

    //<editor-fold defaultstate="collapsed" desc="GET/SET">
    public Collection<Booth> getBooths() {
        return booths;
    }

    public void setBooth(Booth booth) {
        this.booth = booth;
    }

    public void setBooths(Collection<Booth> booths) {
        this.booths = booths;
    }

    public void setDiamondColor(DiamondColor diamondColor) {
        this.diamondColor = diamondColor;
    }

    public void setDiamondGroup(DiamondGroup diamondGroup) {
        this.diamondGroup = diamondGroup;
    }

    public void setDiamondPure(DiamondPure diamondPure) {
        this.diamondPure = diamondPure;
    }

    public void setGemPriceCondition(String gemPriceCondition) {
        this.gemPriceCondition = gemPriceCondition;
    }

    public void setGemWeightCondition(String gemWeightCondition) {
        this.gemWeightCondition = gemWeightCondition;
    }

    public void setNetWeightCondition(String netWeightCondition) {
        this.netWeightCondition = netWeightCondition;
    }

    public void setWagePriceCondition(String wagePriceCondition) {
        this.wagePriceCondition = wagePriceCondition;
    }

    public void setGoldsmith(Goldsmith goldsmith) {
        this.goldsmith = goldsmith;
    }

    public void setJewelryStyle(JewelryStyle jewelryStyle) {
        this.jewelryStyle = jewelryStyle;
    }

    public void setList(Collection<HashMap<String, String>> list) {
        this.list = list;
    }

    public void setProductGold(ProductGold productGold) {
        this.productGold = productGold;
    }

    public void setProductType(String productType) {
        if (productType == null) {
            this.productType = 0;
        } else {
            this.productType = Integer.parseInt(productType);
        }

    }

    public void setSearchService(SearchService searchService) {
        this.searchService = searchService;
    }

    public void setShop(Shop shop) {
        this.shop = shop;
    }

    public Shop getShop() {
        return shop;
    }

    public void setTotalWeightCondition(String totalWeightCondition) {
        this.totalWeightCondition = totalWeightCondition;
    }

    public void setWageCostCondition(String wageCostCondition) {
        this.wageCostCondition = wageCostCondition;
    }

    public Collection<HashMap<String, String>> getList() {
        return list;
    }

    public AnnotateDataBinder getBinder() {
        return binder;
    }

    public Booth getBooth() {
        return booth;
    }

    public DiamondColor getDiamondColor() {
        return diamondColor;
    }

    public DiamondGroup getDiamondGroup() {
        return diamondGroup;
    }

    public DiamondPure getDiamondPure() {
        return diamondPure;
    }

    public String getGemPriceCondition() {
        return gemPriceCondition;
    }

    public String getGemWeightCondition() {
        return gemWeightCondition;
    }

    public Goldsmith getGoldsmith() {
        return goldsmith;
    }

    public JewelryStyle getJewelryStyle() {
        return jewelryStyle;
    }

    public String getNetWeightCondition() {
        return netWeightCondition;
    }

    public ProductGold getProductGold() {
        return productGold;
    }

    public int getProductType() {
        return productType;
    }

    public String getTotalWeightCondition() {
        return totalWeightCondition;
    }

    public String getWageCostCondition() {
        return wageCostCondition;
    }

    public String getWagePriceCondition() {
        return wagePriceCondition;
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="onLoadBooth">
    public void onLoadBooth(ForwardEvent event) {
        booths = shop.getBooths();
        getBinder().loadComponent(searchBooth);
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="doAfterCompose">
    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        booths = shopGenericService.getBooths();
        binder = new AnnotateDataBinder(self);
        self.setAttribute("binder", binder);
        binder.loadAll();
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="onSearch">
    public void onSearch() {
        switch (productType) {
            case Product.TYPE_JEWELRY:
                list = searchService.getJewelryList(shop, booth, jewelryStyle, productGold, goldsmith, totalWeightCondition, searchTotalWeightAmount.doubleValue(), gemWeightCondition, searchGemWeightAmount.doubleValue(),
                        netWeightCondition, searchNetWeightAmount.doubleValue(), wageCostCondition, searchWageCostAmount.doubleValue(), wagePriceCondition, searchWagePriceAmount.doubleValue(), gemPriceCondition, searchGemPriceAmount.doubleValue());
                break;
            case Product.TYPE_DIAMOND:
                list = searchService.getDiamondList(shop, booth, diamondGroup, diamondColor, diamondPure, gemWeightCondition, searchGemWeightAmount.doubleValue());
                break;
            case Product.TYPE_PREMIUMJEWELRY:
                list = searchService.getPremiumList(shop, booth, jewelryStyle, gemWeightCondition, searchGemWeightAmount.doubleValue(), gemPriceCondition, searchGemPriceAmount.doubleValue());
        }
        getBinder().loadComponent(detailDiv);
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="onLoadLeftGrid">
    public void onLoadLeftGrid(ForwardEvent event) {
        switch (productType) {
            case Product.TYPE_JEWELRY:
                searchTotalWeightAmount.setDisabled(false);
                searchNetWeightAmount.setDisabled(false);
                searchWageCostAmount.setDisabled(false);
                searchWagePriceAmount.setDisabled(false);
                searchStlyes.setDisabled(false);
                searchGoldSmith.setDisabled(false);
                searchGold.setDisabled(false);
                searchTotalWeightCondition.setDisabled(false);
                searchNetWeightCondition.setDisabled(false);
                searchWageCostCondition.setDisabled(false);
                searchWagePriceCondition.setDisabled(false);
                searchDiamondGroup.setDisabled(true);
                searchDiamondColor.setDisabled(true);
                searchDiamondPure.setDisabled(true);
                break;
            case Product.TYPE_PREMIUMJEWELRY:
                searchTotalWeightAmount.setDisabled(true);
                searchNetWeightAmount.setDisabled(false);
                searchWageCostAmount.setDisabled(true);
                searchWagePriceAmount.setDisabled(true);
                searchStlyes.setDisabled(false);
                searchGoldSmith.setDisabled(true);
                searchGold.setDisabled(true);
                searchTotalWeightCondition.setDisabled(true);
                searchNetWeightCondition.setDisabled(false);
                searchWageCostCondition.setDisabled(true);
                searchWagePriceCondition.setDisabled(true);
                searchDiamondGroup.setDisabled(true);
                searchDiamondColor.setDisabled(true);
                searchDiamondPure.setDisabled(true);
                break;
            case Product.TYPE_DIAMOND:
                searchTotalWeightAmount.setDisabled(true);
                searchNetWeightAmount.setDisabled(true);
                searchWageCostAmount.setDisabled(true);
                searchWagePriceAmount.setDisabled(true);
                searchStlyes.setDisabled(true);
                searchGoldSmith.setDisabled(true);
                searchGold.setDisabled(true);
                searchTotalWeightCondition.setDisabled(true);
                searchNetWeightCondition.setDisabled(true);
                searchWageCostCondition.setDisabled(true);
                searchWagePriceCondition.setDisabled(true);
                searchDiamondGroup.setDisabled(false);
                searchDiamondColor.setDisabled(false);
                searchDiamondPure.setDisabled(false);
                break;
        }
    }
    //</editor-fold>
}
